using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using EIM_Accounting.Common.StringUtility;

namespace EIM_Accounting
{
    /// <summary>
    /// 合同 合同管理 合同列表
    /// </summary>
    public partial class CP010101 : Form
    {
        BLL.CP010101 cp010101 = new BLL.CP010101();

        public CP010101()
        {
            InitializeComponent();

            DataGridViewColumn dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.DataPropertyName = "ID";
            dgvc.HeaderText = "ID";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);
            dataGridView1.Columns[0].Visible = false;

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.Width = 140;
            dgvc.HeaderText = "合约公司";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.Width = 200;
            dgvc.HeaderText = "预订日期";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.Width = 200;
            dgvc.HeaderText = "实际日期";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvc.DefaultCellStyle.Font = new Font("华文新魏", 12F, FontStyle.Italic);
            dgvc.DefaultCellStyle.ForeColor = Color.DarkGreen;
            dgvc.Width = 80;
            dgvc.HeaderText = "单金";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            dgvc.DefaultCellStyle.Font = new Font("华文新魏", 12F, FontStyle.Italic);
            dgvc.DefaultCellStyle.ForeColor = Color.DarkBlue;
            dgvc.Width = 100;
            dgvc.HeaderText = "总额";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.Columns.Add(dgvc);

            dgvc = new DataGridViewTextBoxColumn();
            dgvc.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.Width = 200;
            dgvc.HeaderText = "备注";
            dgvc.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvc.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            dataGridView1.Columns.Add(dgvc);

            foreach (DataGridViewColumn cdd in dataGridView1.Columns)
            {
                cdd.SortMode = DataGridViewColumnSortMode.NotSortable;
            }
            dataGridView1.EnableHeadersVisualStyles = false;
            dataGridView1.Columns[0].HeaderCell.Style.ForeColor = Color.Yellow;
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.SteelBlue;
            dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.Info;
            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("楷体_GB2312", 14F, FontStyle.Regular);
            dataGridView1.ColumnHeadersHeight = 60;

            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.AllowUserToResizeColumns = false;
            dataGridView1.AllowUserToResizeRows = false;

            dataGridView1.RowHeadersVisible = false;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.Lavender;//System.Drawing.Color.FromArgb(60, 250, 240, 230);
            dataGridView1.AllowUserToOrderColumns = false;

            dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
        }

        private void dataGridView1_DoubleClick(object sender, System.EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1) { return; }
            string contactId = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

            CP010102 cm010102 = new CP010102();
            cm010102.contactId = contactId;

            cm010102.ShowDialog();
            setDataGridView(false);
        }

        private void CP010101_Load(object sender, System.EventArgs e)
        {
            setDataGridView(false);
        }

        private void setDataGridView(bool FinishFlg)
        {
            dataGridView1.Rows.Clear();

            DataSet ds = cp010101.GetDataList(FinishFlg);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string id = dr["ID"].ToString();
                string signComp = dr["SignComp"].ToString();

                string remark = dr["Remark"].ToString();

                dataGridView1.Rows.Add(new string[] { id, signComp, StringHelper.getDateStrWithNewLine(dr["PlanStartDate"],dr["PlanEndDate"]),
                StringHelper.getDateStrWithNewLine(dr["RealStartDate"],dr["RealEndDate"]),StringHelper.getDecimalStr(dr["SingleMoney"]),
                StringHelper.getDecimalStr(dr["TotalMoney"]),remark});
            }
        }

        private void btnRealDate_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1) { return; }
            string contactId = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

            CP010105 cm010105 = new CP010105();
            cm010105.contractID = contactId;

            cm010105.ShowDialog();
            setDataGridView(false);
        }
    }
}